const mongoose = require('mongoose');
const db = require('./db');
const _ = require('lodash');
const baseDao = require('./baseDao');
const Schema = mongoose.Schema;

const messageTypes = [
    {label:"定向发放",value:'oriented'},
    {label:'自动触发',value:'autoTrigger'}
]

const triggers = [
    {label:"注册成功",value:"register"},
    {label:"修改密码",value:"updatePassword"},
    {label:"充值成功",value:"rechargeSuccess"},
    {label:"充值失败",value:"rechangeFailed"},
    {label:"拍卖成功",value:"auctionSuccess"},
    {label:"拍卖失败",value:"auctionFailed"},
    {label:"已发货",value:"delivered"},
    {label:"晒单通过审核",value:"shewApproved"},
    {label:"晒单被驳回",value:"shewReject"},
    {label:"提现结果",value:"withdrawApplicationResult"},
    {label:"提现处理中",value:"withdrawApplicationProcessing"}
]

const messageCfgSchema = new Schema({
	title: { type: String },
    contentTemplate: { type: String }, 
    messageType:{type:String,enum:messageTypes.map(v=>v.value)},


    sendTime:{type:Date},
    receiverList:{type:String},
    sendSms:{type:Boolean,default:false},
    sendNotification: { type: Boolean, default:false},

    trigger:{type:String,enum:triggers.map(v=>v.value)},

    enable: { type:Boolean, default:true},
    createTime:{type:Date,default:Date.now},
    updateTime:{type:Date}
},
{
	collection : 'messageCfg'
});

const MessageCfg = db.model('messageCfg', messageCfgSchema);

const messageCfgDao = Object.assign({

    model: MessageCfg,
    
    getMessageTypes: function(){
        return messageTypes.map(v=>Object.assign({},v));
    },

    getTriggers: function(){
        return triggers.map(v=>Object.assign({},v));
    }

}, baseDao);

module.exports = messageCfgDao;